<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="scroll.css"/>
  <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
  <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <ul class="news">
    <li>
      <span>揭开XX游伪善的面纱</span>
      <span>让真相大白于天下</span>
    </li>
    <li>
      <span>驰誉欢途西安站发声</span>
      <span>长风破浪会有时</span>
    </li>
    <li>
      <span>直挂云帆济沧海</span>
      <span>在宽容中壮大</span>
    </li>
  </ul>
</div>
<div class="container">
  <ul class="product">
    <li><img src="https://img.alicdn.com/bao/upload/i2/140040329086715575/TB2z.PSd9OI.eBjSspmXXatOVXa_!!0-dgshop.jpg" /></li>
    <li><img src="https://img.alicdn.com/bao/upload/i4/155440329072847406/TB2LR6udYWJ.eBjSspdXXXiXFXa_!!0-dgshop.jpg" /></li>
    <li><img src="https://img.alicdn.com/bao/upload/i4/102810329017786180/TB2mgyqas2DjeFjSspnXXb20XXa_!!0-dgshop.jpg" /></li>
    <li><img src="https://img.alicdn.com/bao/upload/i1/135230329030165803/TB2OftTe8yN.eBjSZFgXXXmGXXa_!!2-dgshop.png" /></li>
    <li><img src="https://img.alicdn.com/bao/upload/i3/116800329014989146/TB2DXJ3e6m2.eBjSZFtXXX56VXa_!!0-dgshop.jpg" /></li>
    <li><img src="https://img.alicdn.com/bao/upload/i4/153740329012919326/TB2JLTIdZaK.eBjSspjXXXL.XXa_!!0-dgshop.jpg" /></li>
    <li><img src="https://img.alicdn.com/bao/upload/i3/136030329010126190/TB2nYrqd91I.eBjy0FjXXabfXXa_!!2-dgshop.png" /></li>
  </ul>
</div>
</body>
<script>
  function Scroll(opt) {
    this._pause = 0;
    this.i = 0;
    this.delayTimer = 0;
    if (typeof opt == "object") {
      this.config(opt);
    }
  }
  Scroll.prototype.config = function (opt) {
    this.settings = $.extend({
      dir: "scrollTop"
      , maxSpan: 52
      , speed: 40
      , delay: 1000
      , step : 2
      , selector: ""
      , autoStart: true
      , pauseOnOver: true
    }, opt);

    if (this.settings.pauseOnOver) {
      var _self = this;
      $(this.settings.selector).on("mouseover", function () {
        _self.pause(true);
      });
      $(this.settings.selector).on("mouseout", function () {
        _self.pause(false);
      });
    }
    if (this.settings.autoStart) {
      this.start();
    }
  }
  Scroll.prototype.roll = function () {
    if (this._pause){
      return;
    }
    var span = $(this.settings.selector)[this.settings.dir]();
    if (span < this.settings.maxSpan) {
      span += this.settings.step;
    } else {
      span = 0;
      $(this.settings.selector).children().eq(0).appendTo($(this.settings.selector));
      var _self = this;
      _self.stop();
      _self.delayTimer = setTimeout(function () {
        _self.start();
      }, _self.settings.delay);
    }
    $(this.settings.selector)[this.settings.dir](span);
  };
  Scroll.prototype.pause = function (b) {
    this._pause = b;
  }
  Scroll.prototype.start = function () {
    var _self = this;
    _self.i = setInterval(function () {
      _self.roll();
    }, _self.settings.speed)
  }
  Scroll.prototype.stop = function () {
    clearInterval(this.i);
    clearTimeout(this.delayTimer);
  }

  new Scroll({
    dir: "scrollTop"
    , selector: ".news"
    , speed: 50
    , pauseOnOver: true
    , maxSpan :52
  });
  s1=new Scroll({
    dir: "scrollLeft"
    , selector: ".product"
    , speed: 20
    , step: 5
    , pauseOnOver: true
    , maxSpan :210
    , delay : 1000
  });
</script>
</html>